home *** CD-ROM | disk | FTP | other *** search
- /*
- When creating your project, uncheck OWL,
- uncheck Class Library, select Static
- instead of Dynamic and change the target
- model to Console from GUI.
- Also link glut.lib to your project once its done.
- */
-
- #include <gl/gl.h> // The GL Header File
- #include <gl/glut.h> // The GL Utility Toolkit (Glut) Header
-
- void init ( GLvoid ) // Create Some Everyday Functions
- {
-
- glShadeModel(GL_SMOOTH); // Enable Smooth Shading
- glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
- glClearDepth(1.0f); // Depth Buffer Setup
- glEnable(GL_DEPTH_TEST); // Enables Depth Testing
- //glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
- glEnable ( GL_COLOR_MATERIAL );
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- }
-
- void display ( void ) // Create The Display Function
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
- glLoadIdentity(); // Reset The Current Modelview Matrix
- glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
- glBegin(GL_TRIANGLES); // Drawing Using Triangles
- glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
- glVertex3f( 0.0f, 1.0f, 0.0f); // Top
- glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
- glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
- glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
- glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
- glEnd(); // Finished Drawing The Triangle
- glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
- glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
- glBegin(GL_QUADS); // Draw A Quad
- glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
- glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
- glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
- glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
- glEnd(); // Done Drawing The Quad
-
-
- glutSwapBuffers ( );
- // Swap The Buffers To Not Be Left With A Clear Screen
- }
-
- void reshape ( int w, int h ) // Create The Reshape Function (the viewport)
- {
- GLfloat hw = (GLfloat) h / (GLfloat) w;
-
- glViewport ( 0, 0, w, h );
- glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
- glLoadIdentity ( ); // Reset The Projection Matrix
-
- glFrustum( -1.0, 1.0, -hw, hw, 2.0, 60.0 );
-
- /*
- if ( h==0 ) // Calculate The Aspect Ratio Of The Window
- gluPerspective ( 80, ( float ) w, 1.0, 5000.0 );
- else
- gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
- */
- glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
- glLoadIdentity ( ); // Reset The Model View Matrix
- }
-
- int main ( int argc, char** argv ) // Create Main Function For Bringing It All Together
- {
- glutInit ( &argc, argv ); // Erm Just Write It =)
- glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE ); // Display Mode
- glutInitWindowSize ( 320, 256 ); // If glutFullScreen wasn't called this is the window size
- glutCreateWindow ( "NeHe's OpenGL Framework" ); // Window Title (argv[0] for current directory as title)
- init();
- glutDisplayFunc ( display ); // Matching Earlier Functions To Their Counterparts
- glutReshapeFunc ( reshape );
- reshape(320, 256);
- display();
- glutMainLoop ( ); // Initialize The Main Loop
-
- return 0;
- }
-
-